<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputLabel value="#{messages.Knowledge}"/>
        </ui:define>
        <ui:define name="body">
            <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
            <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
            <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:form styleClass="jsfcrud_list_form" id="myForm">
                <h:panelGrid columns="1">
                    <h:outputLabel value="#{messages.Current}#{messages.Knowledge}"/>
                    <h:panelGrid columns="2" bgcolor="white">
                        <h:outputLabel value="#{messages.Name}"   dir="RTL"/>
                        <h:outputLabel id="name" value="#{knowledgeController.selected.name}" title="#{messages.Name}"/>
                        <h:outputLabel value="#{messages.Detail}" dir="RTL"/>
                        <h:outputText id="detail" value="#{knowledgeController.selected.details}" escape="false"/>
                    </h:panelGrid>
                    <hr/>
                    <c:forEach items="#{edgeamongknowledgeController.getPrecessorEdgeamongknowledge(knowledgeController.selected)}" var="edge">
                        <h:panelGroup>
                            <h:panelGrid columns="2">
                                <h:outputLabel value="#{messages.Predicate}#{messages.Name}"   dir="RTL"/>
                                <h:outputLabel value="#{edge.predicate.pname}"/>
                                <h:outputLabel value="#{messages.Knowledge}#{messages.Name}"   dir="RTL"/>
                                <h:outputLabel value="#{edge.predecessornode.name}"/>
                            </h:panelGrid>
                            <h:commandButton value="#{messages.Delete}" action="#{edgeamongknowledgeControllerA.remove(edge)}" immediate="true"/>
                            <h:commandButton value="#{messages.Return}" action="#{knowledgeController.gotoView()}"/>
                        </h:panelGroup>
                    </c:forEach>
                    <hr/>
                    <!--知识点前驱-->
                    <h:outputLabel value="#{messages.Please}#{messages.Specify}#{messages.Related}#{messages.Knowledge}"/><br/>
                    <h:panelGrid columns="2">
                        <h:outputLabel value="#{messages.Knowledge}"/>
                        <h:selectOneMenu id="knowledge" value="#{edgeamongknowledgeController.relatedKnolwdge}" required="true">
                            <f:selectItem  itemLabel="#{messages.Please} #{messages.Select}"/>
                            <f:selectItems value="#{knowledgeController.getKnowledgeList4Subject(0,knowledgeController.selected)}"/> 
                        </h:selectOneMenu>

                        <h:outputLabel value="#{messages.Predicate}"/>
                        <h:selectOneMenu  id="predicate" value="#{predicateController.selected}" required="true"> 
                            <f:selectItem  itemLabel="#{messages.Please} #{messages.Select}"/>
                            <f:selectItems value="#{predicateControllerA.allList}"/> 
                        </h:selectOneMenu>
                    </h:panelGrid>
                    <hr/>
                    <h:outputLabel value="#{messages.Edge} #{messages.Memo}"/>
                    <h:inputTextarea value="#{edgeamongknowledgeController.selected.memo}" 
                                     p:placeholer="#{messages.Nomorethan}1280"/>
                    <h:outputLabel value="#{messages.Upload}#{messages.Learningresource}"/>
                    <hr/>
                    <!--<h:outputLabel value="2. #{messages.No}#{messages.Upload}"/>-->
                    <h:commandButton value="#{messages.Save}"  action="#{edgeamongknowledgeController.create()}"/>
                </h:panelGrid>

                <h:inputHidden p:id="inputGraph" p:name="inputGraph" value="#{knowledgeController.getKnowledgeRelationship4dagre()}"/>

                <svg width="960" height="600"> <g/></svg>
                <script>
                    var svg = d3.select("svg"),
                            inner = d3.select("svg g"),
                            zoom = d3.zoom().on("zoom", function () {
                        inner.attr("transform", d3.event.transform);
                    });
                    svg.call(zoom);

                    // Create and configure the renderer
                    var render = dagreD3.render();

                    var g;

                    var inputGraph = document.querySelector("#inputGraph");
                    try {
                        g = graphlibDot.read(inputGraph.value);
                    } catch (e) {
                        inputGraph.setAttribute("class", "error");
                        throw e;
                    }

                    g.graph().transition = function (selection) {
                        return selection.transition().duration(500);
                    };

                    // Render the graph into svg g
                    d3.select("svg g").call(render, g);
                </script>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
